home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / TABLC.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  59 lines

  1. ############################################################################
  2. #
  3. #    File:     tablc.icn
  4. #
  5. #    Subject:  Program to tabulate characters in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program tabulates characters and lists each character and
  14. #  the number of times it occurs. Characters are written using
  15. #  Icon's escape conventions.  Line termination characters and other
  16. #  control characters are included in the tabulation.
  17. #  
  18. #  Options: The following options are available:
  19. #  
  20. #       -a   Write the summary in alphabetical order of the charac-
  21. #            ters. This is the default.
  22. #  
  23. #       -n   Write the summary in numerical order of the counts.
  24. #  
  25. #       -u   Write only the characters that occur just once.
  26. #  
  27. ############################################################################
  28. #
  29. #  Links: options
  30. #
  31. ############################################################################
  32.  
  33. link options
  34.  
  35. procedure main(args)
  36.    local ccount, unique, order, s, a, pair, rwidth, opts
  37.    unique := 0                # switch to list unique usage only
  38.    order := 3                # alphabetical ordering switch
  39.  
  40.    opts := options(args,"anu")
  41.    if \opts["a"] then order := 3
  42.    if \opts["n"] then order := 4
  43.    if \opts["u"] then unique := 1
  44.  
  45.    ccount := table(0)            # table of characters
  46.    while ccount[reads()] +:= 1
  47.    a := sort(ccount,order)
  48.    if unique = 1 then {
  49.       while s := get(a) do
  50.      if get(a) = 1 then write(s)
  51.       }
  52.    else {
  53.       rwidth := 0
  54.       every rwidth <:= *!a
  55.       while s := get(a) do
  56.          write(left(image(s),10),right(get(a),rwidth))
  57.       }
  58. end
  59.